package com.ourteam.education.api;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.ourteam.education.dao.CourseDefineDAOQueryBean;
import com.ourteam.education.domain.CourseDefineBean;
import com.ourteam.frame.web.AbstractSearchModel;

public class CourseDefineSearchBean extends AbstractSearchModel<CourseDefineDAOQueryBean> {

	private String courseName;

	private Long[] courseTypeId;

	private String schoolYear;

	private String[] status;

	private String[] teachingMode;

	private String[] chargingMode;

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public Long[] getCourseTypeId() {
		return courseTypeId;
	}

	public void setCourseTypeId(Long[] courseTypeId) {
		this.courseTypeId = courseTypeId;
	}

	public String getSchoolYear() {
		return schoolYear;
	}

	public void setSchoolYear(String schoolYear) {
		this.schoolYear = schoolYear;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	public String[] getTeachingMode() {
		return teachingMode;
	}

	public void setTeachingMode(String[] teachingMode) {
		this.teachingMode = teachingMode;
	}

	public String[] getChargingMode() {
		return chargingMode;
	}

	public void setChargingMode(String[] chargingMode) {
		this.chargingMode = chargingMode;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return CourseDefineBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(CourseDefineDAOQueryBean queryBean) throws Exception {
		
		CourseDefineDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		
		if(StringUtils.isNoneBlank(this.courseName)) {
			criteria.andCourseNameLike(courseName);
		}
		
		if(ArrayUtils.isNotEmpty(this.courseTypeId)) {
			criteria.andCourseTypeIdIn(courseTypeId);
		}
		
		if(StringUtils.isNoneBlank(this.schoolYear)) {
			criteria.andSchoolYearLike(schoolYear);
		}
		
		if(ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(status);
		}
		
		if(ArrayUtils.isNotEmpty(this.chargingMode)) {
			criteria.andChargingModeIn(chargingMode);
		}
		
		if(ArrayUtils.isNotEmpty(this.teachingMode)) {
			criteria.andTeachingModeIn(teachingMode);
		}
	}

}
